package com.example.belong.ggvideo.util;

import android.content.Context;
import android.content.res.AssetManager;

import com.example.belong.ggvideo.util.GsonUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JsonUtils {
    public static final String FILE_NAME="tttt.json";
    /**
     * 获取json
     * @param context
     * @param fileName：文件名
     */
    public static String getJson(Context context ,String fileName){
        StringBuilder buffer = new StringBuilder();
        AssetManager assets = context.getAssets();
        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(assets.open(fileName), "utf-8"));
            String len;
            while ((len= reader.readLine())!=null){
                buffer.append(len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer.toString();

    }

    /**
     * json转object
     */
    private <T> T jsonToObject(String json, Class<T> object) {
       return GsonUtils.instance().jsonToObject(json,object);
    }

}
